<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class HouseController extends Controller
{
   public function getIndex(Request $request){
            //关联查询收藏的商品信息
            $res2=DB::table("tbl_house")
            ->join("tbl_home_user","tbl_house.uid","=","tbl_home_user.id")
            ->join("tbl_goods","tbl_house.gid","=","tbl_goods.id")
            ->where("tbl_house.uid","=",session("home_userid"))
            ->get();
            // dd($res2);
       
        return view('home/house/house',['list'=>$res2]);
  }

  public function getAdd(){
            $gid = $_GET['gid'];
            $uid = session('home_userid');
            //查询数据库中用户是否已经收藏过该商品

            $count = DB::table("tbl_house")->where("gid",$gid)->where("uid",$uid)->count();
           // dd($count);
            if($count<=0){
                //如果没有收藏过，则根据用户id 和商品id 插入数据库收藏表
                $data['uid']=$uid;
                $data['gid']=$gid;
               // dd($data);
                DB::table("tbl_house")->insert($data);
                echo '您已成功收藏商品，请到收藏夹中查看';
            }else{
                echo '您已收藏过此商品，请到收藏夹中查看';
                exit;
            }

  }
        
   
}
